import Vue from 'vue'
import ElementUI from 'element-ui'
import App from './App'
import router from '@/router'
import store from '@/store'
import { isAuth } from '@/common/js/utils'
import '@/common/css/index.scss'
import Print from 'vue-print-nb'
import $ from 'jquery'
import vueg from 'vueg'
import './icons'
import moment from 'moment'

moment.locale('zh-cn')

Vue.use(vueg, router)

Vue.use(ElementUI, { size: 'middle', zIndex: 3000 })
Vue.use(Print)

Vue.config.productionTip = false
Vue.filter('changeTime', (value) => {
  if (value) {
    return value.split(' ')[0]
  }
  return '无'
})
Vue.filter('changeTimeArr', (arr) => {
  if (arr) {
    return arr[0].split(' ')[0] + '～' + arr[1].split(' ')[0]
  }
  return '无'
})
Vue.filter('showTime', (time,flag) => {
  if (time == null) return '无'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    if (('' + time).length === 10) time = parseInt(time) * 1000
    date = new Date(time)
  }
  let y = date.getFullYear()
  let m = date.getMonth() + 1
  m = m < 10 ? '0' + m : m
  let d = date.getDate()
  d = d < 10 ? '0' + d : d
  if (flag == 1) {
    return y+'年'+m+'月'
  }else{
    return y+'年'+m+'月'+d+'日'
  }
})
Vue.prototype.testWay = function(isTest) {
  const map = {
    0: '普通检验',
    1: '留样或稳考',
    2: '只稳考不留样'
  }
  return map[isTest]
}
Vue.prototype.moment = moment
Vue.prototype.calcValidity = function(s,v) {
  moment().locale('zh-cn')
  let e = moment(s).add(v, 'M')
  //如果相等，那么为大至大的转换，比如 5.31->7.31(加2个月)，则需要减1天
  if (moment(s).format('D') == e.format('D')) {
    return e.subtract(1, 'd').format('YYYY-MM-DD HH:mm:ss')
  }else{
    //如果不等，那么为大至小的转换，比如 5.31->6.30(加1个月)，则不需要减1天
    return e.subtract(1, 'months').format('YYYY-MM-DD HH:mm:ss')
  }
}
Vue.prototype.isAuth = isAuth
Vue.prototype.yfb = (id) => {
  return id == 1 || id == 2 || id == 3 || id == 9
}
Vue.prototype.y = (id) => {
  return id == 1
}
Vue.prototype.f = (id) => {
  return id == 2
}
Vue.prototype.b = (id) => {
  return id == 3
}
Vue.prototype.qt = (id) => {
  return id == 9
}
Vue.prototype.zc = (id) => {
  return id == 4 || id == 5
}
Vue.prototype.z = (id) => {
  return id == 4
}
Vue.prototype.c = (id) => {
  return id == 5
}
Vue.prototype.wk = (id) => {
  return id == 6
}
Vue.prototype.ys = (id) => {
  return id == 7
}
Vue.prototype.env = (id) => {
  return id == 8
}
Vue.prototype.getPrintCheckUrl = (checkTypeId, versionNum) => {
  return '/registcheck' + checkTypeId + '-' + versionNum
}
Vue.prototype.getPrintCheckName = (checkTypeName, versionNum) => {
  return checkTypeName + '请验单' + versionNum + '版'
}
Vue.prototype.pickerOptions = {
  disabledDate(time) {
    // 浏览器问题，导致本地时间少一天，所以需要加一天
    return time.getTime() > (Date.now() + (24 * 60 * 60 * 1000));
  },
  shortcuts: [{
    text: '今天',
    onClick(picker) {
      picker.$emit('pick', new Date());
    }
  }, {
    text: '昨天',
    onClick(picker) {
      const date = new Date();
      date.setTime(date.getTime() - 3600 * 1000 * 24);
      picker.$emit('pick', date);
    }
  }, {
    text: '一周前',
    onClick(picker) {
      const date = new Date();
      date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
      picker.$emit('pick', date);
    }
  }]
}
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
